#include <iostream>
#include <queue>
using namespace std;

class Solution
{
public:
    int lastStoneWeight(vector<int>& stones)
    {
        priority_queue<int> heap;
        for (auto& e : stones)
            heap.push(e);
        while (heap.size() > 1)
        {
            int num2 = heap.top();
            heap.pop();
            int num1 = heap.top();
            if (num1 == num2) heap.pop();
            else {
                heap.pop();
                heap.push(num2 - num1);
            }
        }
        return heap.top();
    }
};

int main()
{
    vector<int> stones = { 2, 7, 4, 1, 8, 1 };
    Solution().lastStoneWeight(stones);

    return 0;
}